<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/**
 * 读文件
 **/
function read_file($filename)
{
    $fp = fopen($filename, "r") or die("couldn't open $filename");
    $read = fread($fp, filesize($filename));
    fclose($fp);
    return $read;
}
/**
 * 写文件
 **/
function write_file($filename, $buffer)
{
    $fp = fopen($filename, "w") or die("couldn't open $filename");
    flock( $fp, LOCK_EX );
    $write = fputs($fp, $buffer);
    flock( $fp, LOCK_UN );
    fclose($fp);
    return true;
}
/**
 * 修改(只是追加内容)
 **/
function append_to_file($filename, $buffer)
{
    $fp = fopen($filename, "a") or die("couldn't open $filename");
    flock( $fp, LOCK_EX );
    fputs($fp, $buffer);
    flock( $fp, LOCK_UN );
    fclose($fp);
    return true;
}
/**
 * 测试
 **/
/*$str = read_file('test.txt');
echo $str;
write_file('test2.txt', $str);
append_to_file('test2.txt', "ABCD");*/
